/**
 * @param {number} mainTank
 * @param {number} additionalTank
 * @return {number}
 */
var distanceTraveled = function (mainTank, additionalTank) {
	let ans = 0
	while (mainTank >= 5) {
		mainTank -= 5
		ans += 50
		if (additionalTank > 0) {
			additionalTank--
			mainTank++
		}
	}
	return ans + mainTank * 10
}
var distanceTraveled = (mainTank, additionalTank) => {
	/* 
        每当使用了5升就会少1升：每消耗4升就会加1升
        当只有4升的时候，即使有剩余，也不会加，确保不会计算多余的转移
    */
	return (
		10 *
		(mainTank + Math.min(Math.floor((mainTank - 1) / 4), additionalTank))
	)
}
console.log(distanceTraveled(9, 1))
